<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>照片上传</title>
    <script type="text/javascript" src="https://www.w3school.com.cn/jquery/jquery.js"></script>
</head>
<body>
<form name="fileForm" method="POST" enctype="multipart/form-data" action="/upload">
    <p>
        文件：<input type="file" name="file" multiple/>
    </p>
    <p>
        <input type="button" id="btn" value="submit">
    </p>
    <p>
        上传文件数：<p id="result"></p>
    </p>
</form>
</body>
<script>
    $('#btn').click(function () {
        let count = 0;
        var files = document.fileForm.file.files;
        for(let i = 0; i < files.length;i++){
            var fm = new FormData();
            fm.append('file', files[i]);
            $.ajax(
                {
                    url: '/upload',
                    type: 'POST',
                    data: fm,
                    contentType: false, //禁止设置请求类型
                    processData: false, //禁止jquery对DAta数据的处理,默认会处理
                    //禁止的原因是,FormData已经帮我们做了处理
                    success: function (result) {
                        count++
                        $('#result').text(count);
                    }
                }
            );
        }

    });
</script>
</html>